﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogicLayer;
using System.Collections;
namespace logicunivesityinventorystore.Department

{
    public partial class ChangeCollectionPoint : System.Web.UI.Page
    {
        CollectionPointFacade cf = new CollectionPointFacade();
        EmployeeFacade ef = new EmployeeFacade();
        DepartmentFacade df = new DepartmentFacade();


        BusinessLogicLayer.CollectionPoint collection = new BusinessLogicLayer.CollectionPoint();
        BusinessLogicLayer.Employee employee = new BusinessLogicLayer.Employee();
        BusinessLogicLayer.Department department = new BusinessLogicLayer.Department();

        protected void Page_Load(object sender, EventArgs e)
        {
            string empid = User.Identity.Name;

            employee = ef.FindEmployeeByID(empid);
            department = df.FindDepartmentByDepartmentID(employee.Departmentcode);
            collection = cf.FindCollectionById(department.CollectionPointID);
            lblCurrentCollectionPoint.Text = collection.Location.ToString() + " " + collection.Time.TimeOfDay.ToString() + " am"; //collection time is always in the morning. but to make it simpler to the user concatenated the "am".

            string id = "EngSch";
            TimeSpan t = cf.GetTime(id);
            lblTime.Text = t.ToString();
        }

        protected void ddlCollectionPoints_SelectedIndexChanged(object sender, EventArgs e)
        {



            string id = ddlCollectionPoints.SelectedValue;
            if (id == null)
                id = "EngSch";
            TimeSpan t = cf.GetTime(id);
            lblTime.Text = t.ToString();

           

        }

        protected void btnChange_Click(object sender, EventArgs e)
        {
            department.CollectionPointID = ddlCollectionPoints.SelectedValue;
            df.UpdateCollectionID(department.DepartmentCode, department.CollectionPointID);

            Response.Redirect("HomePage_Department.aspx");


        }

   

     
    }
}